const app = getApp()

Page({
  data: {
    testNum: '1758',

    array: [
      {
        picture: "",
        information: "",
        type:""
      }
    ],
    selectType: 0,
    arrayList: [],
    // changeType: {
    //   selectType: '',
    //   arr: [
    //     {
    //       picture:"",
    //       peopleNum: "",
    //       information: "",
    //       detail:""
    //     }  
    //   ]
    // }
  },
  onLoad: function (options) {
    console.log(options,"options");
    let openid = options.openid || "";
    console.log(openid,"openid");
    console.log('Welcome to Mini Code')
    var that = this;
    that.onChange();
    // that.onClickSwitch();
    let task = tt.request({
      url: "https://dycps.aikeai.group/testService/initPage/test",
      success(res) {
        console.log(that,"that");
        console.log(`request调用成功 ${res}`);
        console.log(res,"res");
        that.setData({
          arrayList:  res.data
        })
        console.log(that.data.arrayList,"arrayList") 
      },
      fail(res) {
        console.log(`request调用失败`);
      }
    });

    // let findCount = tt.request({
    //   url: 'https://dycps.aikeai.group/testService/findCount', // 目标服务器url
    //   success: (res) => {
    //     console.log(res,"findCount");
    //     that.setData({
    //       testNum:  res.data
    //     })
    //   }
    // });

    let hotTest = tt.request({
      url: 'https://dycps.aikeai.group/testService/findHotTest', // 目标服务器url
      success: (res) => {
        console.log(res,"hotTest");
        that.setData({
          array:  res.data
        })
      }
    });
  },
  onChange: function(){
    tt.request({
      url: 'https://dycps.aikeai.group/testService/findOtherTest', // 目标服务器url
      success: (res) => {
        console.log(this,"this");
        this.setData({
          array:  res.data
        })
      }
    });
  },
  onClickSwitch: function(event) {
      console.log(event);
      // console.log(event.target.id,"event.target.id");
      let id;
      switch(event.target.id){
        case 'funny': 
          id = 1;
          break; 
        case 'heart': 
          id = 2;
          break;
        case 'emotion': 
          id = 3;
          break;
        case 'character': 
          id = 4;
          break;
        case 'love': 
          id = 5;
          break;
        case 'ability':
          id = 6; 
          break;
        case 'job': 
          id = 7;
          break;
        case 'elaborate': 
          id = 8;
          break;
      }
      console.log(id,"id");
      tt.request({
        url: 'https://dycps.aikeai.group/testService/findCategoryPage', // 目标服务器url
        data:{
          categoryid: id
        },
        success: (res) => {
          // console.log(this, 'this')
          console.log(res,"findCategoryPage");
          this.setData({
            arrayList: res.data,
            selectType: id
          });
        }
      });
  },
  quickTest: function(e){
    console.log(e);
    console.log(e.target.id,"e.target.timuid")
    let timuid = e.target.id;
    tt.navigateTo({
      url: `/pages/testing/testing?timuid=${timuid}`,
      success(res) {
        console.log(`${res}`);
      },
      fail(res) {
        console.log(`navigateTo调用失败`);
      }
    });
  
  }
})
